package com.ymatou.iapi.liveseller.testcase;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymatou.iapi.liveseller.parameter.CreateSellerPreVideoBean;
import com.ymatou.iapi.liveseller.parameter.LiveDto;
import com.ymatou.iapi.liveseller.service.CreateSellerLiveCall;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.selleraccount.parameter.SellerBaseInfo;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.utils.DesUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

import jdk.nashorn.internal.ir.annotations.Ignore;

/**
 * 创建互动直播 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_CreateSellerLive {
	private static CreateSellerLiveBean createsellerliveBean;
	private static CreateSellerLiveCall createsellerliveCall;
	private static LiveRoomWapper liveRoomWapper;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("创建互动直播");
	}

	@Before
	public void caseUp() {
		createsellerliveBean = new CreateSellerLiveBean();
		createsellerliveCall = new CreateSellerLiveCall();
		liveRoomWapper = new LiveRoomWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(createsellerliveCall.getOpurl());
		liveRoomWapper = null;
	}

	@After
	public void caseDown() {

		Logger.end();
	}

	private void verifyDB(LiveRoom livedto, int liveid) throws Exception {
		Logger.comment("数据库验证");
		LiveRoom dblive = liveRoomWapper.selectLiveRoomById(liveid);
		
		Logger.verifyEquals(livedto.getGroupId(), dblive.getGroupId(), "验证GroupId");
//		Logger.verifyEquals(livedto.getStartTime(), dblive.getStartTime().substring(0, 19), "验证StartTime");
//		Logger.verifyEquals(livedto.getEndTime(), dblive.getEndTime().substring(0, 19), "验证EndTime");
//		Logger.verifyEquals(livedto.getLatitude(), dblive.getLatitude(), "验证Latitude");
		Logger.verifyEquals(livedto.getLongitude(), dblive.getLongitude(), "验证Longitude");
		Logger.verifyEquals(livedto.getLiveAddress(), dblive.getLiveAddress(), "验证LiveAddress");
		Logger.verifyEquals(livedto.getLiveCover(), dblive.getLiveCover(), "验证LiveCover");
		Logger.verifyEquals(livedto.getLiveTitle(), dblive.getLiveTitle(), "验证LiveTitle");
		Logger.verifyEquals(livedto.getShoppingAddress(), dblive.getShoppingAddress(), "验证ShoppingAddress");
		Logger.verifyEquals(livedto.getPreVideoHeight(), dblive.getPreVideoHeight(), "验证PreVideoHeight");
		Logger.verifyEquals(livedto.getPreVideoLength(), dblive.getPreVideoLength(), "验证PreVideoLength");
		Logger.verifyEquals(livedto.getPreVideoPic(), dblive.getPreVideoPic(), "验证PreVideoPic");
		Logger.verifyEquals(livedto.getPreVideoWidth(), dblive.getPreVideoWidth(), "验证PreVideoWidth");
		Logger.verifyEquals(livedto.getSellerName(), dblive.getSellerName(), "验证SellerName");
		Logger.verifyEquals(livedto.getUserId(), dblive.getUserId(), "验证UserId");
		Logger.verifyEquals(livedto.getPreVideoUrl(), dblive.getPreVideoUrl(), "验证PreVideoUrl");
		Logger.verifyNotNull(dblive.getPushUrl(), "验证PushUrl");
		String pushurl = DesUtil.decrypt(dblive.getPushUrl(), DesUtil.DES_KEY_STRING, DesUtil.DES_IVPARAMETER);
		Map mpush = FormatUtil.httpStringToMap(pushurl.split("\\?")[1]);
		String sourcepushsecret = LiveRoomCallService.LiveAntiKey + LiveRoomCallService.BizId + "_" + EnvSetup.getEnv().toUpperCase() + "_" + liveid
				+ mpush.get("txTime").toString();
		String pushtxsecret = TestDataManager.getMD5(sourcepushsecret.getBytes());
		Logger.verifyEquals(mpush.get("txSecret").toString(), pushtxsecret, "验证pushtxsecret");
		// rtmp://11418.livepush.myqcloud.com/live/11418_52?txSecret=80747057322436595a4aaf0b1cb3d71a&txTime=59EAEEE1
		Logger.verifyNotNull(dblive.getPlayUrl(), "验证PlayUrl");
//		Logger.verifyNotNull(dblive.getContinentName(), "验证ContinentName");
		Logger.debug(FormatUtil.beanToGSONString(JUserCallService.getSellerInfo(livedto.getUserId())));
		SellerBaseInfo sinfo = JUserCallService.getSellerInfo(livedto.getUserId());
		Logger.verifyEquals(sinfo.getContinentName(),dblive.getContinentName(), "验证ContinentName");
		Logger.verifyEquals(sinfo.getLiveCountry(), dblive.getCountryId(), "验证CountryId");
		// String
		// playUrl=DesUtil.decrypt(dblive.getPlayUrl(),DesUtil.DES_KEY_STRING,DesUtil.DES_IVPARAMETER);
		// Map mplay=FormatUtil.httpStringToMap(playUrl.split("\\?")[1]);
		// String
		// playtxsecret=TestDataManager.getMD5(sourcepushsecret.getBytes());
		// Logger.verifyEquals(mplay.get("txSecret").toString(), playtxsecret,
		// "验证pushtxsecret");
		// rtmp://11418.liveplay.myqcloud.com/live/11418_52?txSecret=80747057322436595a4aaf0b1cb3d71a&txTime=59EAEEE1
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_001() {
		Logger.start(true, "创建互动直播成功");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoomCallService.AutoCloseLiveRoomByUserId(createsellerliveBean.getLiveDto().getUserId());
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("200", createsellerliveCall.getString("Code"), "验证Code");
			JsonObject data = createsellerliveCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals(true, data.get("Result").getAsBoolean(), "验证Result");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_CreateSellerLive_002() {
		Logger.start(true, "不输入userid失败");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			createsellerliveBean.getLiveDto().setUserId(null);
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("Code"), "验证Code");
			Logger.verifyIsContains("买手Id不能为空", createsellerliveCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	@org.junit.Ignore
	public void Tc_CreateSellerLive_003() {
		Logger.start(true, "不输入LiveTitle失败");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			createsellerliveBean.getLiveDto().setLiveTitle(null);
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("Code"), "验证Code");
			Logger.verifyEquals("标题不能为空", createsellerliveCall.getString("Msg"), "验证Msg");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_004() {
		Logger.start(true, "创建互动直播成功,标题包含特殊字符");
		try {
			// sql添加：set names utf8mb4;
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoomCallService.AutoCloseLiveRoomByUserId(createsellerliveBean.getLiveDto().getUserId());
			createsellerliveBean.getLiveDto().setLiveTitle("测试特殊字符;😑😊😳");
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("200", createsellerliveCall.getString("Code"), "验证Code");
			JsonObject data = createsellerliveCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals(true, data.get("Result").getAsBoolean(), "验证Result");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_CreateSellerLive_005() {
		Logger.start(true, "开始时间早于当前时间失败");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			createsellerliveBean.getLiveDto().setStartTime(YMTDateUtil.getBeforeOrNextMunite(-100));
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("Code"), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}


	@Test
	@Category({ P3.class })
	@TestCase
	@org.junit.Ignore
	public void Tc_CreateSellerLive_007() {
		Logger.start(true, "开始时间晚于30天失败");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			createsellerliveBean.getLiveDto().setStartTime(YMTDateUtil.getBeforeOrNextDay(31));
//			createsellerliveBean.getLiveDto().setEndTime(YMTDateUtil.getBeforeOrNextDay(32));
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("Code"), "验证Code");
			Logger.verifyIsContains("直播开始时间最多只能设置为", createsellerliveCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_008() {
		Logger.start(true, "标题长度小于18互动直播创建失败");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			createsellerliveBean.getLiveDto().setLiveTitle("        Test        ");
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("Code"), "验证Code");
			Logger.verifyIsContains("卖点信息长度需在", createsellerliveCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_009() {
		Logger.start(true, "标题长度小大于28互动直播创建失败");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			createsellerliveBean.getLiveDto().setLiveTitle("测试标题长度大于二十八的情况试试这样能否创建");
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("Code"), "验证Code");
			Logger.verifyIsContains("卖点信息长度需在", createsellerliveCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_0091() {
		Logger.start(true, "标题长度为28互动直播创建成功");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoomCallService.AutoCloseLiveRoomByUserId(createsellerliveBean.getLiveDto().getUserId());
			createsellerliveBean.getLiveDto().setLiveTitle("1122334455667788990011223344");
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("200", createsellerliveCall.getString("Code"), "验证Code");
			Logger.verifyIsContains("操作成功", createsellerliveCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_0092() {
		Logger.start(true, "去掉前后空格，标题长度为28互动直播创建成功");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoomCallService.AutoCloseLiveRoomByUserId(createsellerliveBean.getLiveDto().getUserId());
			createsellerliveBean.getLiveDto().setLiveTitle("     112233445566778899  11223344     ");
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("200", createsellerliveCall.getString("Code"), "验证Code");
			Logger.verifyIsContains("操作成功", createsellerliveCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
		
	}

	@Test
	@Category({ P3.class })
	@TestCase
	@org.junit.Ignore
	public void Tc_CreateSellerLive_010() {
		Logger.start(true, "直播时间大于4小时失败");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			createsellerliveBean.getLiveDto().setStartTime(YMTDateUtil.getBeforeOrNextMunite(10));
//			createsellerliveBean.getLiveDto().setEndTime(YMTDateUtil.getBeforeOrNextMunite(60 * 4 + 11));
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("Code"), "验证Code");
			Logger.verifyEquals("直播时间不能大于4小时", createsellerliveCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_011() {
		Logger.start(true, "重复创建互动直播失败");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			createsellerliveCall.callService();
			Logger.verifyEquals("201", createsellerliveCall.getString("Code"), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@org.junit.Ignore
	public void Tc_CreateSellerLive_012() {
		Logger.start(true, "创建2个未来的互动直播成功");
		try {
			//可以创建2个未来直播 20180508
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoomCallService.AutoCloseLiveRoomByUserId(createsellerliveBean.getLiveDto().getUserId());
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			createsellerliveBean.getLiveDto().setGroupId(TestDataManager.getRandomNum(13));
			createsellerliveBean.getLiveDto().setStartTime(YMTDateUtil.getBeforeOrNextMunite(220));
//			createsellerliveBean.getLiveDto().setEndTime(YMTDateUtil.getBeforeOrNextMunite(300));
			createsellerliveCall.callService();
			Logger.verifyEquals("200", createsellerliveCall.getString("Code"), "验证Code");
//			Logger.verifyEquals("即将开始直播只能创建一场，不可重复创建", createsellerliveCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_013() {
		Logger.start(true, "正在直播推流的直播时创建一个未来的互动直播、失败");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			Thread.sleep(3000);
			createsellerliveBean.getLiveDto().setGroupId(String.valueOf(YMTDateUtil.getDate().getTime()));
			createsellerliveBean.getLiveDto().setStartTime(YMTDateUtil.getBeforeOrNextMunite(2000));
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			
			JsonObject data = createsellerliveCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("500", createsellerliveCall.getString("Code"), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_CreateSellerLive_014() {
		Logger.start(true, "不输入PreVideoPic失败");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			createsellerliveBean.getLiveDto().setPreVideoPic(null);
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("Code"), "验证Code");
			Logger.verifyEquals("预告短片封面不能为空", createsellerliveCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_CreateSellerLive_015() {
		Logger.start(true, "不输入PreVideoUrl失败");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			createsellerliveBean.getLiveDto().setPreVideoUrl(null);
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("Code"), "验证Code");
			Logger.verifyEquals("预告短片不能为空", createsellerliveCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_CreateSellerLive_016() {
		Logger.start(true, "不输入LiveAddress成功，可为空");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			createsellerliveBean.getLiveDto().setLiveAddress(null);
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("200", createsellerliveCall.getString("Code"), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_CreateSellerLive_017() {
		Logger.start(true, "不输入StartTime失败");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			createsellerliveBean.getLiveDto().setStartTime(null);
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("400", createsellerliveCall.getString("Code"), "验证Code");
			Logger.verifyEquals("开始时间不能为空", createsellerliveCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			
			Logger.fail(e);
		}
	}


//	@Test
//	@Category({ P1.class })
//	@TestCase
//	public void Tc_CreateSellerLive_019() {
//		Logger.start(true, "groupid为空失败");
//		try {
//			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
//			LiveRoomCallService.AutoCloseLiveRoomByUserId(createsellerliveBean.getLiveDto().getUserId());
//			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
//			createsellerliveBean.getLiveDto().setGroupId(null);
//			createsellerliveCall.setData(createsellerliveBean);
//			createsellerliveCall.callService();
//			Logger.verifyEquals("400", createsellerliveCall.getString("Code"), "验证Code");
//			Logger.verifyIsContains("不能为空", createsellerliveCall.getString("Msg"), "验证Msg");
//		} catch (Exception e) {
//			Logger.fail(e);
//		}
//	}



	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_022() {
		Logger.start(true, "groupid重复，失败");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoomCallService.AutoCloseLiveRoomByUserId(createsellerliveBean.getLiveDto().getUserId());
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			LiveRoomCallService.AutoCloseLiveRoomByUserId(createsellerliveBean.getLiveDto().getUserId());
			createsellerliveCall.callService();
			Logger.verifyEquals("500", createsellerliveCall.getString("Code"), "验证Code");
			Logger.verifyIsContains("系统异常", createsellerliveCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_034() {
		Logger.start(true, "服务端创建互动直播 GroupId 为空");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoomCallService.AutoCloseLiveRoomByUserId(createsellerliveBean.getLiveDto().getUserId());
			createsellerliveBean.getLiveDto().setGroupId(null);
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("200", createsellerliveCall.getString("Code"), "验证Code");
			JsonObject data = createsellerliveCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals(true, data.get("Result").getAsBoolean(), "验证Result");
			
			verifyDBGroupId(createsellerliveBean.getLiveDto(), data.get("LiveId").getAsInt());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_035() {
		Logger.start(true, "快速创建互动直播成功");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			createsellerliveBean.getLiveDto().setSellerLiveSource(1);
			LiveRoomCallService.AutoCloseLiveRoomByUserId(createsellerliveBean.getLiveDto().getUserId());
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("200", createsellerliveCall.getString("Code"), "验证Code");
			JsonObject data = createsellerliveCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals(true, data.get("Result").getAsBoolean(), "验证Result");
			verifyDB(createsellerliveBean.getLiveDto(), data.get("LiveId").getAsInt());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
//	@Test
//	@Category({ P1.class })
//	@TestCase
//	public void Tc_CreateSellerLive_035() {
//		Logger.start(true, "创建互动直播 新增 SellerLiveSource  为0 默认创建");
//		try {
//			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
//			LiveRoomCallService.AutoCloseLiveRoomByUserId(createsellerliveBean.getLiveDto().getUserId());
//			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
//			createsellerliveCall.setData(createsellerliveBean);
//			createsellerliveCall.callService();
//			Logger.verifyEquals("200", createsellerliveCall.getString("Code"), "验证Code");
//			JsonObject data = createsellerliveCall.getJsonObject().get("Data").getAsJsonObject();
//			Logger.verifyEquals(true, data.get("Result").getAsBoolean(), "验证Result");
//			verifyDB(createsellerliveBean.getLiveDto(), data.get("LiveId").getAsInt());
//		} catch (Exception e) {
//			Logger.fail(e);
//		}
//	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_036() {
		Logger.start(true, "创建互动直播 新增 SellerLiveSource  为1  快速创建.然后查询直播间商品");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(createsellerliveBean.getLiveDto().getUserId());
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			createsellerliveBean.getLiveDto().setSellerLiveSource(0);
			createsellerliveBean.getLiveDto().setProductIdList(Arrays.asList(productId));
			LiveRoomCallService.AutoCloseLiveRoomByUserId(createsellerliveBean.getLiveDto().getUserId());
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("200", createsellerliveCall.getString("Code"), "验证Code");
			JsonObject data = createsellerliveCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals(true, data.get("Result").getAsBoolean(), "验证Result");
			verifyDB(createsellerliveBean.getLiveDto(), data.get("LiveId").getAsInt());
			
			JsonArray LiveProductIdList = LiveRoomCallService.QueryLiveProductIdList(data.get("LiveId").getAsInt());
			Logger.verifyEquals(productId, LiveProductIdList.get(0).getAsString(), "验证商品");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_037() {
		Logger.start(true, "创建互动直播 新增 SellerLiveSource  为1  快速创建、预告片与开始时间可以不填");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(createsellerliveBean.getLiveDto().getUserId());
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			createsellerliveBean.getLiveDto().setSellerLiveSource(1);
			//预告片可不填
			createsellerliveBean.getLiveDto().setStartTime(null);
			createsellerliveBean.getLiveDto().setPreVideoUrl(null);
			createsellerliveBean.getLiveDto().setPreVideoPic(null);
			createsellerliveBean.getLiveDto().setPreVideoLength(null);
			createsellerliveBean.getLiveDto().setPreVideoWidth(null);
			createsellerliveBean.getLiveDto().setPreVideoHeight(null);
			createsellerliveBean.getLiveDto().setProductIdList(Arrays.asList(productId));
			LiveRoomCallService.AutoCloseLiveRoomByUserId(createsellerliveBean.getLiveDto().getUserId());
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			
			Logger.verifyEquals("200", createsellerliveCall.getString("Code"), "验证Code");
			JsonObject data = createsellerliveCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals(true, data.get("Result").getAsBoolean(), "验证Result");
			verifyDB(createsellerliveBean.getLiveDto(), data.get("LiveId").getAsInt());
			
			JsonArray LiveProductIdList = LiveRoomCallService.QueryLiveProductIdList(data.get("LiveId").getAsInt());
			
			Logger.verifyEquals(productId, LiveProductIdList.get(0).getAsString(), "验证商品");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_038() {
		Logger.start(true, "创建互动直播 、经纬，直播地，可为空");
		try {
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoomCallService.AutoCloseLiveRoomByUserId(createsellerliveBean.getLiveDto().getUserId());
			createsellerliveBean.getLiveDto().setGroupId(null);
			createsellerliveBean.getLiveDto().setLongitude(null);
			createsellerliveBean.getLiveDto().setLatitude(null);
			createsellerliveBean.getLiveDto().setLiveAddress(null);
			createsellerliveBean.getLiveDto().setSellerName(null);
			createsellerliveBean.getLiveDto().setLiveActivityId(null);
			createsellerliveBean.setRequestId(TestDataManager.getRandomUUID().toString());
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("200", createsellerliveCall.getString("Code"), "验证Code");
			JsonObject data = createsellerliveCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals(true, data.get("Result").getAsBoolean(), "验证Result");
			verifyDBDefault(createsellerliveBean.getLiveDto(), data.get("LiveId").getAsInt());
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateSellerLive_039() {
		Logger.start(true, "当前有正在推流的直播，不能给快速创建、但是可以创建预告");
		try {
			List<Userinfo> list = new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			
			LiveRoomCallService.AutoCloseLiveRoomByUserId(uinfo.getUserId());
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(uinfo);
			createsellerliveBean.getLiveDto().setSellerLiveSource(1);
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("200", createsellerliveCall.getString("Code"), "验证Code");
			int asInt = createsellerliveCall.getJsonObject().get("Data").getAsJsonObject().get("LiveId").getAsInt();
			LiveRoomCallService.SellerLiveOnline(asInt, uinfo.getUserId());
			createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(uinfo);
			createsellerliveBean.getLiveDto().setSellerLiveSource(1);
			createsellerliveCall.setData(createsellerliveBean);
			createsellerliveCall.callService();
			Logger.verifyEquals("201", createsellerliveCall.getString("Code"), "验证Code");
			Logger.verifyEquals("当前有正在直播的场次哦~", createsellerliveCall.getString("Msg"), "验证Code");
			CreateSellerPreVideoBean initCreatesellerPreVideoBean = LiveRoomCallService.initCreatesellerPreVideoBean(uinfo.getUserId());
			LiveRoomCallService.CreatesellerPreVideo(initCreatesellerPreVideoBean);
			

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	
	
	
	
	
	
	private void verifyDBDefault(LiveRoom livedto, int liveid) throws Exception {
		Logger.comment("数据库验证");
		LiveRoom dblive = liveRoomWapper.selectLiveRoomById(liveid);
		
//		Logger.verifyEquals(livedto.getGroupId(), dblive.getGroupId(), "验证GroupId");
		Logger.verifyEquals("31.2300", dblive.getLatitude(), "验证Latitude");
		Logger.verifyEquals("121.4700", dblive.getLongitude(), "验证Longitude");
		Logger.verifyEquals(livedto.getLiveAddress(), dblive.getLiveAddress(), "验证LiveAddress");
		Logger.verifyEquals(livedto.getLiveCover(), dblive.getLiveCover(), "验证LiveCover");
		Logger.verifyEquals(livedto.getLiveTitle(), dblive.getLiveTitle(), "验证LiveTitle");
		Logger.verifyEquals(livedto.getShoppingAddress(), dblive.getShoppingAddress(), "验证ShoppingAddress");
		Logger.verifyEquals(livedto.getPreVideoHeight(), dblive.getPreVideoHeight(), "验证PreVideoHeight");
		Logger.verifyEquals(livedto.getPreVideoLength(), dblive.getPreVideoLength(), "验证PreVideoLength");
		Logger.verifyEquals(livedto.getPreVideoPic(), dblive.getPreVideoPic(), "验证PreVideoPic");
		Logger.verifyEquals(livedto.getPreVideoWidth(), dblive.getPreVideoWidth(), "验证PreVideoWidth");
		Logger.verifyEquals(livedto.getSellerName(), dblive.getSellerName(), "验证SellerName");
		Logger.verifyEquals(livedto.getUserId(), dblive.getUserId(), "验证UserId");
		Logger.verifyEquals(livedto.getPreVideoUrl(), dblive.getPreVideoUrl(), "验证PreVideoUrl");
		Logger.verifyNotNull(dblive.getPushUrl(), "验证PushUrl");
		String pushurl = DesUtil.decrypt(dblive.getPushUrl(), DesUtil.DES_KEY_STRING, DesUtil.DES_IVPARAMETER);
		Map mpush = FormatUtil.httpStringToMap(pushurl.split("\\?")[1]);
		String sourcepushsecret = LiveRoomCallService.LiveAntiKey + LiveRoomCallService.BizId + "_" + EnvSetup.getEnv().toUpperCase() + "_" + liveid
				+ mpush.get("txTime").toString();
		String pushtxsecret = TestDataManager.getMD5(sourcepushsecret.getBytes());
		Logger.verifyEquals(mpush.get("txSecret").toString(), pushtxsecret, "验证pushtxsecret");
		// rtmp://11418.livepush.myqcloud.com/live/11418_52?txSecret=80747057322436595a4aaf0b1cb3d71a&txTime=59EAEEE1
		Logger.verifyNotNull(dblive.getPlayUrl(), "验证PlayUrl");
//		Logger.verifyNotNull(dblive.getContinentName(), "验证ContinentName");
		Logger.debug(FormatUtil.beanToGSONString(JUserCallService.getSellerInfo(livedto.getUserId())));
		SellerBaseInfo sinfo = JUserCallService.getSellerInfo(livedto.getUserId());
		Logger.verifyEquals(sinfo.getContinentName(),dblive.getContinentName(), "验证ContinentName");
		Logger.verifyEquals(sinfo.getLiveCountry(), dblive.getCountryId(), "验证CountryId");
		// String
		// playUrl=DesUtil.decrypt(dblive.getPlayUrl(),DesUtil.DES_KEY_STRING,DesUtil.DES_IVPARAMETER);
		// Map mplay=FormatUtil.httpStringToMap(playUrl.split("\\?")[1]);
		// String
		// playtxsecret=TestDataManager.getMD5(sourcepushsecret.getBytes());
		// Logger.verifyEquals(mplay.get("txSecret").toString(), playtxsecret,
		// "验证pushtxsecret");
		// rtmp://11418.liveplay.myqcloud.com/live/11418_52?txSecret=80747057322436595a4aaf0b1cb3d71a&txTime=59EAEEE1
	}
	
	
	
	
	private void verifyDBGroupId(LiveRoom livedto, int liveid) throws Exception {
		Logger.comment("数据库验证");
		LiveRoom dblive = liveRoomWapper.selectLiveRoomById(liveid);
		
		Logger.verifyNotNull(dblive.getGroupId(), "验证GroupId不为空");
//		Logger.verifyEquals(livedto.getGroupId(), dblive.getGroupId(), "验证GroupId");
		Logger.verifyEquals(livedto.getStartTime(), dblive.getStartTime().substring(0, 19), "验证StartTime");
//		Logger.verifyEquals(livedto.getLatitude(), dblive.getLatitude(), "验证Latitude");
		Logger.verifyEquals(livedto.getLongitude(), dblive.getLongitude(), "验证Longitude");
		Logger.verifyEquals(livedto.getLiveAddress(), dblive.getLiveAddress(), "验证LiveAddress");
		Logger.verifyEquals(livedto.getLiveCover(), dblive.getLiveCover(), "验证LiveCover");
		Logger.verifyEquals(livedto.getLiveTitle(), dblive.getLiveTitle(), "验证LiveTitle");
		Logger.verifyEquals(livedto.getShoppingAddress(), dblive.getShoppingAddress(), "验证ShoppingAddress");
		Logger.verifyEquals(livedto.getPreVideoHeight(), dblive.getPreVideoHeight(), "验证PreVideoHeight");
		Logger.verifyEquals(livedto.getPreVideoLength(), dblive.getPreVideoLength(), "验证PreVideoLength");
		Logger.verifyEquals(livedto.getPreVideoPic(), dblive.getPreVideoPic(), "验证PreVideoPic");
		Logger.verifyEquals(livedto.getPreVideoWidth(), dblive.getPreVideoWidth(), "验证PreVideoWidth");
		Logger.verifyEquals(livedto.getSellerName(), dblive.getSellerName(), "验证SellerName");
		Logger.verifyEquals(livedto.getUserId(), dblive.getUserId(), "验证UserId");
		Logger.verifyEquals(livedto.getPreVideoUrl(), dblive.getPreVideoUrl(), "验证PreVideoUrl");
		Logger.verifyNotNull(dblive.getPushUrl(), "验证PushUrl");
		String pushurl = DesUtil.decrypt(dblive.getPushUrl(), DesUtil.DES_KEY_STRING, DesUtil.DES_IVPARAMETER);
		Map mpush = FormatUtil.httpStringToMap(pushurl.split("\\?")[1]);
		String sourcepushsecret = LiveRoomCallService.LiveAntiKey + LiveRoomCallService.BizId + "_" + EnvSetup.getEnv().toUpperCase() + "_" + liveid
				+ mpush.get("txTime").toString();
		String pushtxsecret = TestDataManager.getMD5(sourcepushsecret.getBytes());
		Logger.verifyEquals(mpush.get("txSecret").toString(), pushtxsecret, "验证pushtxsecret");
		// rtmp://11418.livepush.myqcloud.com/live/11418_52?txSecret=80747057322436595a4aaf0b1cb3d71a&txTime=59EAEEE1
		Logger.verifyNotNull(dblive.getPlayUrl(), "验证PlayUrl");
//		Logger.verifyNotNull(dblive.getContinentName(), "验证ContinentName");
		Logger.debug(FormatUtil.beanToGSONString(JUserCallService.getSellerInfo(livedto.getUserId())));
		SellerBaseInfo sinfo = JUserCallService.getSellerInfo(livedto.getUserId());
		Logger.verifyEquals(sinfo.getContinentName(),dblive.getContinentName(), "验证ContinentName");
		Logger.verifyEquals(sinfo.getLiveCountry(), dblive.getCountryId(), "验证CountryId");
		// String
		// playUrl=DesUtil.decrypt(dblive.getPlayUrl(),DesUtil.DES_KEY_STRING,DesUtil.DES_IVPARAMETER);
		// Map mplay=FormatUtil.httpStringToMap(playUrl.split("\\?")[1]);
		// String
		// playtxsecret=TestDataManager.getMD5(sourcepushsecret.getBytes());
		// Logger.verifyEquals(mplay.get("txSecret").toString(), playtxsecret,
		// "验证pushtxsecret");
		// rtmp://11418.liveplay.myqcloud.com/live/11418_52?txSecret=80747057322436595a4aaf0b1cb3d71a&txTime=59EAEEE1
	}
	
	
}